/* 人才模块　*/
/* by Simon 20150515 */

//获取职位子分类
function getSubPosition(parent_no,curr_no){
    if(parent_no=='') return false;
    var selected = '';
    $.ajax({
        type:"get",
        url:"/?m=hchhr&c=index&a=load_position&parent_no="+parent_no,
        data:'',
        dataType:"json",
        success:function(data){
            $.each(data,function(index,val){
                if(curr_no!='' && val.position_no==curr_no){
                    selected = 'selected';
                }
                else{
                    selected = '';
                }
                $("select[name='position2']").append("<option value='"+val.position_no+"' "+selected+">"+val.position_name+"</option>");
           });
        }
    });
}

//获取行业子分类
function getSubIndustry(parent_no,curr_no){
    if(parent_no=='') return false;
    var selected = '';
    $.ajax({
        type:"get",
        url:"/?m=hchhr&c=index&a=load_industry&parent_no="+parent_no,
        data:'',
        dataType:"json",
        success:function(data){
                $.each(data,function(index,val){
                    if(curr_no!='' && val.industry_no==curr_no){
                        selected = 'selected';
                    }
                    else{
                        selected = '';
                    }
                    $("select[name='industry2']").append("<option value='"+val.industry_no+"' "+selected+">"+val.industry_name+"</option>");
        });
        }
    });
}

//获取城市
function getCity(parent_no,curr_no){
    if(parent_no=='') return false;
    var selected = '';
    $.ajax({
        type:"get",
        url:"/?m=hchhr&c=position&a=load_city&parent_no="+parent_no,
        data:'',
        dataType:"json",
        success:function(data){
            $.each(data,function(index,val){
                if(curr_no!='' && val.area_no==curr_no){
                    selected = 'selected';
                }
                else{
                    selected = '';
                }
                $("select[name='city']").append("<option value='"+val.area_no+"' "+selected+">"+val.area_name+"</option>");
            });
        }
    });
}

//发布职位 表单验证
function checkPosition(the)
{
    if(the.job_name.value==''){
        alert('请填写职位名称！');
        the.job_name.focus();
        return false;
    }

    if(the.position.value==''){
        alert('请选择职位大类！');
        the.position.focus();
        return false;
    }
    if(the.position2.value==''){
        alert('请选择职位小类！');
        the.position2.focus();
        return false;
    }

    if(the.industry.value==''){
        alert('请选择行业大类！');
        the.industry.focus();
        return false;
    }
    if(the.industry2.value==''){
        alert('请选择行业小类！');
        the.industry2.focus();
        return false;
    }
    if(the.province.value==''){
        alert('请选择省份！');
        the.province.focus();
        return false;
    }
    if(the.city.value==''){
        alert('请选择城市！');
        the.city.focus();
        return false;
    }
    if(the.job_money.value==''){
        alert('请选择职位月薪！');
        the.job_money.focus();
        return false;
    }
    if(the.job_nature.value==''){
        alert('请选择工作性质！');
        the.job_nature.focus();
        return false;
    }
	job_editor.sync(); //同步编辑器内容 Kindediter
    if(the.job_desc.value==''){
        alert('请填写职位描述！');
        //the.job_desc.focus();
		job_editor.focus();
        return false;
    }
    if(the.job_num.value==''){
        alert('请填写招聘人数！');
        the.job_num.focus();
        return false;
    }
    if(the.job_endtime.value==''){
        alert('请选择截止日期！');
        the.job_endtime.focus();
        return false;
    }
    if(the.job_linkman.value==''){
        alert('请填写联系人姓名！');
        the.job_linkman.focus();
        return false;
    }
    if(the.job_tel.value==''){
        alert('请填写联系电话！');
        the.job_tel.focus();
        return false;
    }
    the.position_name.value=the.position.options[the.position.selectedIndex].text;
    the.position2_name.value=the.position2.options[the.position2.selectedIndex].text;
    the.industry_name.value=the.industry.options[the.industry.selectedIndex].text;
    the.industry2_name.value=the.industry2.options[the.industry2.selectedIndex].text;
    the.province_name.value=the.province.options[the.province.selectedIndex].text;
    the.city_name.value=the.city.options[the.city.selectedIndex].text;

    the.btn_submit.value = '提交中...';
    the.btn_submit.disabled=true;
	return true;
}
//选择日期
function selectdate(lang)
{
    var date = new Date(Date());
    date = date.valueOf();
    date = date + 1*24*60*60*1000; //明天的日期
    date = new Date(date);
    var tomorrow = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    if(lang=='en')
    {
        WdatePicker({isShowClear:false,readOnly:true,skin:'ext',doubleCalendar:false,dateFmt:'yyyy-MM-dd',minDate:tomorrow,lang:'en'});
    }
    else
    {
        WdatePicker({isShowClear:false,readOnly:true,skin:'ext',doubleCalendar:false,dateFmt:'yyyy-MM-dd',minDate:tomorrow});
    }
}